﻿using MediatR;
using S.EarTag.API.Mediator.MediatorCommand.MarkCommand;
using S.EarTag.Domain.Model;
using S.EarTag.Infrastructure.Repository.Interface.IEarTagRepository;

namespace S.EarTag.API.Mediator.MediatorCommandHandler.MarkCommandHandler
{
    public class EarTagOrMarkCommandHandler : IRequestHandler<EarTagOrMarkCommand, bool>
    {
        private readonly IEarTagOrMarkModelRepository _earTagOrMarkModelRepository;
        public EarTagOrMarkCommandHandler(IEarTagOrMarkModelRepository earTagOrMarkModelRepository)
        {
            _earTagOrMarkModelRepository = earTagOrMarkModelRepository;
        }
        /// <summary>
        /// 添加耳标和电子耳标的关系表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<bool> Handle(EarTagOrMarkCommand request, CancellationToken cancellationToken)
        {
            return await _earTagOrMarkModelRepository.AddAsync(new EarTagOrMarkModel
            {
                EarTagId = request.EarTagId,
                MarkId = request.MarkId,
            });
        }
    }
}
